#include "book.h"
#include "ui_book.h"
#include<QSqlTableModel>
#include <QDebug>

book::book(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::book)
{
    ui->setupUi(this);
}

book::~book()
{
    delete ui;
}

void book::on_pushButton_2_clicked()
{
        this->close();
}

void book::setuser(QString username){
    user=username;
}
void book::printinfo(QString username)
{

}

void book::on_pushButton_clicked()
{
    //qDebug()<<user;
    QSqlTableModel*mode= new QSqlTableModel(ui->tableView);
    mode->setTable("book1");
    mode->setEditStrategy(QSqlTableModel::OnManualSubmit);
    //查询操作
    mode->setFilter(QObject::tr("username = '%1'").arg(user)); //查询当前用户
    mode->select();
    mode->removeColumn(0);//不显示第一列id
    mode->setHeaderData(0,Qt::Horizontal,tr("username"));
    mode->setHeaderData(1, Qt::Horizontal, tr("carname"));
    mode->setHeaderData(1, Qt::Horizontal, tr("time"));
    mode->setHeaderData(1, Qt::Horizontal, tr("place_id"));
    mode->submitAll();
    ui->tableView->setModel(mode);
}
